home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-01-26 | 4.5 KB | 173 lines | [TEXT/R*ch] |
- Dynamic Localization
-
- OSErr ResFile2Resource(Str32 *fileName, short vRefNum, long dirID, short languageID);
- {
- // see description of parameters below
-
- OSErr err;
- short refNum;
- long eof;
- Handle tHandle;
-
- // Open the resource fork of the file for BLOCK reads
- if (err = HOpenRF(vRefNum,dirID,fileName,fsRdPerm,&refNum)) goto exit:
-
- // Get the size of the resource fork
- if (err = GetEOF(refNum, &eof)) goto exitErr;
-
- // Create a handle to hold the entire resource fork
- tHandle = NewHandle(eof);
- if (err = MemError()) goto exitErr;
-
- // Read the entire resource fork into our handle
- if (err = FSRead(refNum, &eof, *tHandle)) goto exitErr;
-
- // The current resource file is our installer application
- // Add this entire resource fork to our installer application
- AddResource(tHandle,'Lirs',languageID,"\p");
- if (err = ResError()) goto exitErr;
-
- WriteResource(tHandle);
- err = ResError();
-
- // Release memory occupied by this resource
- ReleaseResource(tHandle);
- tHandle = nil;
-
- exitErr:
- FSClose(refNum);
- if (tHandle) DisposeHandle(tHandle);
-
- exit:
- return err;
- }
-
-
- Language Magic
-
- // Assume English in case something fails
- gLanguageCode = 0;
-
- // The following chunk of code was graciously provided to me by a engineer at // Adobe Systems, THANKS!
- // Make sure Script Manager calls are available
- if (TrapAvailable(_ScriptUtil)) {
-
- // Get the ID of the current system font and use it to find out
- // the script code
- scriptCode = Font2Script(GetSysFont());
-
- // use the script code to find out the language code for that script
- gLanguageCode = GetScript(scriptCode,smScriptLang);
-
- // "GetScript(scriptCode, smScriptLang)" doesn't return the
- // correct language code on KanjiTalk 6.0.7-J, if it returns zero and if
- // the current script is not Roman, we directly get the language code
- // from the itlb resource.
- if (gLanguageCode == 0 && scriptCode != 0) {
- if (tHandle = GetResource('itlb', scriptCode)) {
- gLanguageCode = (*(ItlbRecord **)tHandle)->itlbLang;
- }
- }
-
- }
-
- // Add 1000 to get the resource ID of localized resources
- gLanguageCode += 1000;
-
-
- Localizing File Names
-
- // See if there are any localized filenames
- tFilesHdl = Get1Resource('Flnm', gLanguageCode);
- if (tFilesHdl) {
- .. Our installer contains a handle of filenames, so we need to call routine to .. replace the original names with these localized filenames.
- ReleaseResource(tFIlesHdl);
- }
-
- Localizing Installer Resources
-
- // See if there are any localized resources.
- tHandle = Get1Resource('Lirs',gLanuageCode);
- if (tHandle) {
- DetachResource(tHandle);
-
- // Store the size of the resource
- count = GetHandleSize(tHandle);
-
- // Call routine to find a volume that is large enough to create a file the // size of the resource.
- vRefNum = FindValidVolume(count);
-
- if (vRefNum) {
- // Come up with a unique filename
- NumToString(TickCount(),tFileName);
-
- // Create file to the root directory (dirID = 2)
- err = HCreateResFile(vRefNum, 2, tFileName);
- if (err) goto doDispose;
-
- // Open the Resource fork for block writing
- err = HOpenRF(vRefNum, 2, tFileName, &refNum);
- if (err) goto doDispose;
-
- // Write out resource to create the file's resource fork
- err = FSWrite(refNum, &count,*tHandle);
-
- FSClose(refNum);
- if (err) goto doDispose;
-
- // Open the resource file we just created
- gExtraResRefNum = HOpenResFile(vRefNum, 2, tFileName, fsRdPerm);
- }
-
- doDispose:
- DisposeHandle(tHandle);
- }
-
-
- Clean Up After Yourself
-
- // Cleanup
- if (gExtraResRefNum != -1) {
- // Since we don't store this filename anywhere, we need to
- // call PBGetFCBInfo to get the filename.
-
- FCBPBRec pb;
- OSErr err;
- Str32 tStr;
-
- pb.ioFCBIndx = 0; // We're not indexing
- pb.ioVRefNum = 0; // 0 = All open files
- pb.ioRefNum = gExtraResRefNum; // Refnum of our resource file
- pb.ioNamePtr = tStr; // Storage place for the name
- err = PBGetFCBInfo(&pb, false);
- if (!err) {
- // Close the Resource File before trying to delete it
- CloseResFile(gExtraResRefNum);
-
- // Delete the Resource File now that we have the vRefNum, directory ID,
- // and the Filename
- err = HDelete(pb.ioFCBVRefNum, pb.ioFCBParID, tStr);
- }
- }
-
-
- Tipping is Not a City in China
-
- // Copying the Resource Fork from one file to another…
- HOpenRF(sourceFile… &sourceRefNum);
- HOpenRF(destFile… &destRefNum);
- GetEOF(sourceRefNum,&sourceSize);
- CopyBytes(sourceRefNum,destRefNum,sourceSize);
- FSClose(sourceRefNum);
- FSClose(destRefNum);
-
- // If you need to, then delete some resources…
- SetResLoad(false);
- destRefNum = HOpenResFile(destFile…);
- Get1Resource();
- RmveResource();
- CloseResFile(destRefNum);
- SetResLoad(true);
-
-
-